﻿using Appliaction.AppServices.Inv;
using Appliaction.Dto.Inv;
using Appliaction.IAppServices.Inv;
using AutoMapper;
using Domain.Entitys.Inv;
using Domain.IRepositorys.Inv;
using EFCore.Repositorys.Inv;
using Microsoft.AspNetCore.Mvc;
using static StackExchange.Redis.Role;

namespace API.Controllers.Inv
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class Inv_othoutordController : Controller
    {

        private readonly IMapper _mapper;
        private readonly IInv_othoutordServices _inv_othoutordService;

        public Inv_othoutordController(IInv_othoutordServices _inv_othoutordService, IMapper mapper)
        {
            this._inv_othoutordService = _inv_othoutordService;
            _mapper = mapper;
        }
        [HttpGet]
        public JsonResult inv_othoutord_Async(string ? searchKeyword, string ? Othoutord_type, int currentPage, int pageSize)
        {
            return new JsonResult(_inv_othoutordService.inv_othoutordAsync(searchKeyword, Othoutord_type, currentPage, pageSize));
        }
        [HttpGet]
        public Task<int> inv_othoutord_Count(string ? searchKeyword, string ? Othoutord_type)
        {
            return _inv_othoutordService.inv_othoutordCount(searchKeyword, Othoutord_type);
        }

        /// <summary>
        /// 查看详情信息
        /// </summary>
        /// <param name="Othoutord_code"></param>
        /// <returns></returns>
        [HttpGet]
        public async  Task<JsonResult> iInvothproddetailslSelect(string Othoutord_code)
        {
            var result = await _inv_othoutordService.iInv_othproddetailslSelect(Othoutord_code);
            return new JsonResult(result);
        }



        /// <summary>
        /// 删除--其他出库单
        /// </summary>
        /// <param name="othoutord_id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Inv_othoutord_delete(int othoutord_id)
        {
          return _inv_othoutordService.Inv_othoutord_delete(othoutord_id);
        }
        /// <summary>
        /// 修改审核状态--其他出库单
        /// </summary>
        /// <param name="inv_Othoutord"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Inv_othoutord_examineUpdate(Inv_othoutord_examineUpdateDto inv_Othoutord)
        {
           return _inv_othoutordService.Inv_othoutord_examineUpdate(inv_Othoutord);
        }



        /// <summary>
        /// 根据编号查询其他出库单信息
        /// </summary>
        /// <param name="trf_code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Inv_trf_SelectCode(string othoutord_code)
        {

            var result = await _inv_othoutordService.Inv_trf_SelectCode(othoutord_code);
            return new JsonResult(result);
        }


        /// <summary>
        /// 根据编码查询其他出库单的详情信息
        /// </summary>
        /// <param name="trf_code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Inv_trf_SelectDetail(string othoutord_code)
        {
            var result = await _inv_othoutordService.Inv_trf_SelectDetail(othoutord_code);
            return new JsonResult(result);
        }

        /// <summary>
        /// 根据其他出库单的编码去查询Id来添加详情信息
        /// </summary>
        /// <param name="otgwr_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<int> othproddetailsSelect_id(string otgwr_code)
        {
            return _inv_othoutordService.othproddetailsSelect_id(otgwr_code);
        }

        /// <summary>
        /// 添加其他出库单信息
        /// </summary>
        /// <param name="inv_Othoutord"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<int> Inv_othoutordAdd(Inv_othoutordAddDto inv_Othoutord)
        {
            return _inv_othoutordService.Inv_othoutordAdd(inv_Othoutord);
        }

        // <summary>
        /// 添加明细表的信息--其他出库单
        /// </summary>
        /// <param name="inv_Othwrproddtl"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> Inv_othproddetails([FromBody] List<Inv_othproddetailsAddDto> entities)
        {
            int result = await _inv_othoutordService.Inv_othproddetails(entities);
            return result;
        }

        /// <summary>
        /// 修改出库状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<int> Inv_othproddetails_updateType(int id)
        {

            return _inv_othoutordService.Inv_othproddetails_updateType(id);
        }


        /// <summary>
        /// 修改出库单和同一时间修改出库库单详情信息库单--详情出库单
        /// </summary>
        /// <param name="inv_Othoutord"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Inv_othoutord_update([FromBody] Inv_OthoutordUpdateMerage inv_OthoutordUpdateMerage)
        {
           return new JsonResult(await _inv_othoutordService.Inv_othoutord_update(inv_OthoutordUpdateMerage));
        }
    }
}
